

import 'package:flui/flui.dart';
import 'package:flutter/material.dart';
import 'package:fzcgx_app/network/http.dart';
import 'package:fzcgx_app/ui/base/base_view_model.dart';
import 'package:fzcgx_app/ui/my/worker/model/worker_education_background_model.dart';
import 'package:fzcgx_app/ui/widget/bottom_sheet_widget.dart';

class WorkerEducationBackgroundViewModel extends BaseViewModel {
  WorkerEducationBackgroundModel model;
  TextEditingController nameController = TextEditingController();
  TextEditingController tizhongController = TextEditingController();
  TextEditingController jiguanController = TextEditingController();
  TextEditingController zhuanyeController = TextEditingController();
  TextEditingController minzuController = TextEditingController();
  TextEditingController gongzuonianxianController = TextEditingController();
  TextEditingController zhengzhimianmaoController = TextEditingController();
  TextEditingController hukoudizhiController = TextEditingController();
  TextEditingController xianzhudizhiController = TextEditingController();
  TextEditingController jinjilianxirenController = TextEditingController();
  TextEditingController jinjilianxirendianhuaController = TextEditingController();
  TextEditingController chushengnianyueController = TextEditingController();
  
  
  WorkerEducationBackgroundViewModel() {
    this.setState(ViewState.Loading);
  }
  void requestApi() {
    Http.instance.post<WorkerEducationBackgroundModel>(
        'app/call/getusers_baseinfo_gr', null, onSuccess: (data) {
      if (data != null) {
        model = data;
        nameController.text=model.name;
        tizhongController.text=model.tizhong;
        jiguanController.text=model.jiguan;
        minzuController.text=model.minzu;
        gongzuonianxianController.text=model.gongzuonianxian;
        zhengzhimianmaoController.text=model.zhengzhimianmao;
        hukoudizhiController.text=model.hukoudizhi;
        xianzhudizhiController.text=model.xianzhudizhi;
        jinjilianxirenController.text=model.jinjilianxiren;
        jinjilianxirendianhuaController.text=model.jinjilianxirendianhua;
        chushengnianyueController.text=model.chushengnianyue;
        zhuanyeController.text=model.zhuanye;
        this.setState(ViewState.Success);
      } else {
        this.setState(ViewState.Empty);
      }
    }, onError: (error) {
      this.setState(ViewState.Error);
    }, onFail: (fail) {
      this.setState(ViewState.Error);
    });
  }

  void onPostApi(BuildContext context) {
    // if (legalNameController.text.toString().isEmpty) {
    //   FLToast.showText(text: '请输入法人姓名');

    //   return;
    // }
    // if (legalMobileController.text.toString().isEmpty) {
    //   FLToast.showText(text: '请输入您的手机号');

    //   return;
    // }
    // if (comTelController.text.toString().isEmpty) {
    //   FLToast.showText(text: '请输入您的座机号');

    //   return;
    // }
    var dismiss = FLToast.loading(text: '正在保存...');
    Http.instance.post('app/call/setusers_baseinfo_gr', {
      // 'com_name': comNameController.text,
      // 'com_tel': comTelController.text,
      // 'legal_mobile': legalMobileController.text,
      // 'legal_name': legalNameController.text,
      // 'legal_sex':model.legalSex,
      
    }, onSuccess: (data) {
      FLToast.showSuccess(text:'保存成功');
      dismiss();
      Navigator.pop(context);
    }, onError: (error) { dismiss();}, onFail: (fail) { dismiss();});
  }
 void onShowBottomSheet(BuildContext context){
    showDialog(
    barrierDismissible: true,//是否点击空白区域关闭对话框,默认为true，可以关闭
    context: context,
    builder: (BuildContext context) {
      var list = List();
      list.add('男');
      list.add('女');
      
      return BottomSheetWidget(
        list: list,
        onItemClickListener: (index) async {
          print( list[index]);
          model.sex= list[index].toString()=='男'?'1':'2';
          notifyListeners();
          Navigator.pop(context);
        },
      );
    });
  }
void onShowBottomMaritalStatusSheet(BuildContext context){
    showDialog(
    barrierDismissible: true,//是否点击空白区域关闭对话框,默认为true，可以关闭
    context: context,
    builder: (BuildContext context) {
      var list = List();
      list.add('单身');
      list.add('结婚');
      
      return BottomSheetWidget(
        list: list,
        onItemClickListener: (index) async {
          print( list[index]);
          model.hunyinzhuangtai= list[index].toString()=='单身'?'1':'2';
          notifyListeners();
          Navigator.pop(context);
        },
      );
    });
  }
void onShowBottomBirthDateSheet(BuildContext context){
    showDialog(
    barrierDismissible: true,//是否点击空白区域关闭对话框,默认为true，可以关闭
    context: context,
    builder: (BuildContext context) {
      var list = List();
      list.add('单身1');
      list.add('结婚2');
      
      return BottomSheetWidget(
        list: list,
        onItemClickListener: (index) async {
          print( list[index]);
          model.chushengnianyue= list[index].toString()=='单身'?'1':'2';
          notifyListeners();
          Navigator.pop(context);
        },
      );
    });
  }
}

